package com.efast.dmom.mes.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.efast.dmom.mes.bean.ProductRoute;
import com.efast.dmom.mes.bean.ResultBean;
import com.efast.dmom.mes.bean.Route;
import com.efast.dmom.mes.bean.RouteStep;
import com.efast.dmom.mes.datahandlers.entity.ProductRouteDataHandler;
import com.efast.dmom.mes.datahandlers.entity.RouteDataHandler;
import com.efast.dmom.mes.service.RouteService;

/**
 * @author Aaron Liu
 * @version Creation Time：2020年1月8日 上午9:36:33
 */

@Service
public class RouteServiceImpl implements RouteService {

	@Autowired
	private RouteDataHandler routeDataHandler;
	
	@Autowired
	private ProductRouteDataHandler productRouteDataHandler;

	@Override
	public void saveRoute(Route route) {
		routeDataHandler.save(route);
	}

	@Override
	public ResultBean removeRoute(long routeId) {
		ResultBean resultBean = new ResultBean(true," ");
		List<ProductRoute> productRouteList = productRouteDataHandler.getProductRouteListByRouteId(routeId);
		if (productRouteList != null && productRouteList.size() > 0) {
			resultBean.setSuccess(false);
			resultBean.setMessage("该工艺路线被产品工艺所引用，无法删除！");
			return resultBean;
		}
		routeDataHandler.removeRouteObjById(routeId);
		resultBean.setSuccess(true);
		resultBean.setMessage("删除成功！");
		return resultBean;
	}

	@Override
	public List<RouteStep> addRouteStep(Route route, List<RouteStep> stepList) {
		return routeDataHandler.addRouteStep(route, stepList);
	}

	@Override
	public Route createRoute(String routeName) {
		return routeDataHandler.createRoute(routeName);
	}
	
	@Override
	public boolean isRouteExist(String routeName) {
		return routeDataHandler.isExist(routeName); 
	}
	
}
